<?php
/**
 * Created by PhpStorm.
 * User: 陈艺赫
 * Date: 2018/5/4
 * Time: 11:32
 */

namespace app\user\model;

use think\Model;

class Group extends Model
{
    /*
     * @param 用户id
     * @return array 当前用户用户组ids
     * */
    public static function getGroupIds($user_id)
    {
        $group_ids_list = User::get($user_id)->group_ids;
        $group_ids_list = explode(',', $group_ids_list);
        return $group_ids_list;
    }

    /*
     * @param 用户id
     * @return array 当前用户用户组所有数据
     * */
    public static function getGroup($user_id)
    {
        $group_ids_list = User::get($user_id)->group_ids;
        $group_ids_list = explode(',', $group_ids_list);
        $group_list = Group::all(['id' => ['in', $group_ids_list], 'status' => 1])->toArray();
        return $group_list;
    }

    /*
    * @param 用户组id
    * @return array 当前用户组所有权限
    * */
    public function getGroupFunction($group_id)
    {
        $func_list = self::get($group_id)->func_ids;
        $func_list = explode(',', $func_list);
        $funcs = Functions::where('id', 'in', $func_list)->column('identify');
        return $funcs;
    }

    /*
     * @param 用户组id
     * @return array 用户组所有可用方法ID
     * */
    public static function getGroupFunctionAllInfo($group_id)
    {
        $func_list = self::get($group_id)->func_ids;
        $func_list = explode(',', $func_list);
        $funcs = Functions::where('id', 'in', $func_list)->co('id');
        return $funcs;
    }

    /*
     * 获取当前用户组的所有菜单id
     * */
    public static function getGroupMenuIds($group_id)
    {
        $menu_list = self::get($group_id)->menu_ids;
        $menu_list = explode(',', $menu_list);
        return $menu_list;
    }
}